package com.wangxl.rabbitmqdemo.conf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Configuration
@Slf4j
public class MQConfig {

    @Resource
    RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        /**
         * 配置消息发送回调操作
         */
        rabbitTemplate.setConfirmCallback((correlationData,ack,cause)->{
            if(ack){
                log.info("send message success----{}",correlationData.getReturnedMessage());
            }else{
                log.info("send message fail----{}",cause);
            }
        });
        rabbitTemplate.setReturnCallback((message,replyCode,replyText,exchange,routingKey)->{
            log.info("send message fail----{}",message.getMessageProperties().getMessageId());
        });
    }
}
